package com.openbravo.pos.panels.link;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import com.openbravo.data.loader.key.KeyBuilder;
import com.openbravo.pos.panels.event.ProductChangedListener;

import cn.ekuma.data.ui.swing.AbstractDTOTableModel;
import cn.ekuma.epos.datalogic.I_DataLogicSales;

@SuppressWarnings("serial")
public abstract class AbstractProductSelectTablePanel<T> extends AbstractProductLinkTablePanel<T> implements I_DeleteAblePanel{

	public AbstractProductSelectTablePanel(I_DataLogicSales dlSales,final AbstractDTOTableModel<T> tableModel) {
		super(dlSales,tableModel);
		jXTable1.addMouseListener(new MouseAdapter(){
			@Override
			public void mouseClicked(MouseEvent e) {
				int selectVCol=jXTable1.getSelectedRow();
				if(e.getClickCount()==2&&selectVCol>-1){
					fireProductChangedListener(getProductId(tableModel.getObj(jXTable1.convertRowIndexToModel(selectVCol))));
				}
			}
	    });
		jXTable1.setRequestFocusEnabled(false);
		jXTable1.setFocusable(false);
    }


	public void addProductChangedListener(ProductChangedListener l) {
		listenerList.add(ProductChangedListener.class, l);
	}

	public void removeProductChangedListener(ProductChangedListener l) {
		listenerList.remove(ProductChangedListener.class, l);
	}

	public void fireProductChangedListener(String pId) {
		for(ProductChangedListener l:listenerList.getListeners(ProductChangedListener.class))
			l.baseBeanChanged(KeyBuilder.getKey(pId), null);
	}

	public abstract String getProductId(T obj);


	@Override
	public boolean deactivate() {
		
		return true;
	}
	
	
	
}